package com.nordstrom;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.archive.crawler.datamodel.CandidateURI;
import org.archive.crawler.postprocessor.FrontierScheduler;

public class NordStromFrontierScheduler extends FrontierScheduler {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		
	String regEx_nordstrom_c = "shop\\.nordstrom\\.com/c/(.*?)\\?origin=brandindex";
	String regEx_nordstrom_s = "shop\\.nordstrom\\.com/s/";
	Pattern pat_c = Pattern.compile(regEx_nordstrom_c); 
	Pattern pat_s = Pattern.compile(regEx_nordstrom_s);
	Matcher mat_c = null;
	Matcher mat_s = null;

	public NordStromFrontierScheduler(String name) {
		super(name);
	}
	
	protected void schedule(CandidateURI caUri) {
		String uri = caUri.toString();
		mat_c = pat_c.matcher(uri);
		mat_s = pat_s.matcher(uri);
		if("dns:shop.nordstrom.com".equals(uri)){
		  getController().getFrontier().schedule(caUri);
		}
		else if(mat_c.find()){
		//System.out.println("@@  "+uri);
		  getController().getFrontier().schedule(caUri);
		}
		else if(mat_s.find()){
//		System.out.println("===="+uri);
		  getController().getFrontier().schedule(caUri);
			}
       
    }
	
	public static void main(String args[]){
		
		String s = "http://shop.nordstrom.com/c/adrianna-papell-plus-size-dresses?origin=brandindex";  
		String regEx = "shop\\.nordstrom\\.com/c/(.*?)\\?origin=brandindex";
		Pattern pat = Pattern.compile(regEx);  
		Matcher mat = pat.matcher(s);  
		boolean rs = mat.find(); 
		if(rs){
			System.out.println("@@@@@"+mat.group(0));
		}
		
	}

}
